
package openHome.dao;

 
import java.io.IOException;
import java.io.Reader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class MySqlConexion {
    private static MySqlConexion instance;
    public MySqlConexion() {

    }

    public static MySqlConexion getInstance(){
        if(instance == null){
            instance = new MySqlConexion();
        }
        return instance;
    }

     public Connection getConnection() {
        Connection cn = null;
        Properties prop;
        try{
            prop = new Properties();
            prop.load(MySqlConexion.class.getResourceAsStream("ConexionBD.properties")); 
            Class.forName(prop.getProperty("driver"));
            String URL = prop.getProperty("url");
            String USER = prop.getProperty("user");
            String PASS = prop.getProperty("pass");
            
            cn = DriverManager.getConnection(URL, USER, PASS);
           
        }catch(IOException ex ) {
           System.out.println(ex.getMessage());
        }catch(SQLException ex) {
           System.out.println(ex.getMessage());
        }catch(Exception ex) {
           System.out.println(ex.getMessage());
        }

        return cn;
    }
}
